Hệ thống quản lý trường học bằng PHP / MySQLi
1 <?php
2 include('connect.php');
3
4 if(isset($_POST["Importfee"])){
5
6 $filename=$_FILES["file"]["tmp_name"];
7
8
9 if($_FILES["file"]["size"] > 0)
10 {
11 $file = fopen($filename, "r");
12 while (($getData = fgetcsv($file, 10000, ",")) !== FALSE)
13 {
14
15
16 $sql = "INSERT into fee (reciept,method,refno,student_id,tdate,amount)
17 values ('".$getData[0]."','".$getData[1]."','".$getData[2]."','".$getData[3]."','".$getData[4]."','".$getData[5]."')";
18 $result = mysqli_query($db, $sql);
19 if(!isset($result))
20 {
21 echo "<script type=\"text/javascript\">
22 alert(\"Invalid File:Please Upload CSV File.\");
23 window.location = \"csvfee.php\"
24 </script>";
25 }
26 else {
27 echo "<script type=\"text/javascript\">
28 alert(\"CSV File has been successfully Imported.\");
29 window.location = \"csvfee.php\"
30 </script>";
31 }
32 }
33
34 fclose($file);
35 }
36 }
37 ?>
38
39 <?php
40
41 if(isset($_POST["Exportfee"])){
42
43 header('Content-Type: text/csv; charset=utf-8');
44 header('Content-Disposition: attachment; filename=data.csv');
45 $output = fopen("php://output", "w");
46 fputcsv($output, array('Reciept #', 'Method','Ref #', 'Student ID', 'Date','Course ID','Term ID','Amount','Captured By'));
47 $query = "SELECT * from fee ORDER BY reciept ASC";
48 $result = mysqli_query($db, $query);
49 while($row = mysqli_fetch_assoc($result))
50 {
51 fputcsv($output, $row);
52 }
53 fclose($output);
54 }
55
56 ?>